<template>
  <el-container>
    <el-form ref="loginForm"
             :model="userInfo"
             :rules="rules">
      <!-- 标题 -->
      <h1>房产管理系统</h1>
      <!-- 用户名 -->
      <el-form-item prop="identifier">
        <el-input placeholder="请输入用户名"
                  prefix-icon='el-icon-user-solid'
                  v-model="userInfo.identifier"> </el-input>
      </el-form-item>

      <!-- 密码 -->
      <el-form-item prop="password">
        <el-input placeholder="请输入密码"
                  prefix-icon='el-icon-s-goods'
                  v-model="userInfo.password"></el-input>
      </el-form-item>
      <!-- 登录按钮 -->
      <el-button type="primary" style="height:50px"
                 @click="LoginFN">登录</el-button>
      <!-- 测试账号密码 -->
      <div class="tips"
           style="cursor:pointer;">
        <span>没有账号？</span>
        <span @click="$router.push('/register')">免费注册</span>
        <!-- <span style="margin-right:20px;">账号:admin </span>
        <span> 密码:adminadmin </span> -->
      </div>
    </el-form>
  </el-container>
</template>

<script>
// import {loginForm} from '@/api/user'
export default {
  data() {
    return {
      // 用户登录信息
      userInfo: {
        identifier: 'admin', //用户名或者邮箱
        password: 'adminadmin',
      },
      userData: {},
      // 表单校验
      rules: {
        username: [
          {
            required: true,
            message: '用户名或者邮箱不能为空',
            trigger: 'blur',
          },
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 12, trigger: 'blur' },
        ],
      },
    }
  },
  created() {
    // console.dir(this.$store.dispatch);
  },
  methods: {
    // 登录按钮处理函数
    async LoginFN() {
      // 1.检验表单 用 $refs获取到组件,再用 elementUI里的 validate 方法校验
      await this.$refs.loginForm.validate()
      await this.$store.dispatch('user/getToken', this.userInfo)
      // localStorage.setItem('houseToken',this.userData.jwt)
      // 提示用户
      this.$message.success('登录成功')
      // 跳转页面
      this.$router.push('/')
    },
  },
}
</script>

<style lang="less" scoped>
.el-form {
  width: 500px;
  position: relative;
  margin: 150px auto;
  h1 {
    color: #fff;
    text-align: center;
    font-size: 40px;
    margin-bottom: 20px;
  }

  /deep/.el-input__inner {
    height: 50px;
    background: rgba(255, 255, 255, 0.4);
  }

  .el-button {
    width: 100%;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    margin-top: 20px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
}
.el-container {
  width: 100vw;
  height: 100vh;
  background: url('../../assets/11.jpg.png') no-repeat;
  background-size: cover;
}
</style>